//
//  WBVisitorView.m
//  sinaWeibo
//
//  Created by 李江波 on 2016/11/14.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

#import "WBVisitorView.h"
#import <Masonry.h>

@interface WBVisitorView ()

@property(nonatomic ,weak) UIImageView *bigImg;
@property(nonatomic ,weak) UILabel *titleLab;

@property(nonatomic ,weak) UIImageView *bigHouse;
@property(nonatomic ,weak) UIImageView *bgImg;


@end

@implementation WBVisitorView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

-(void)setupUI{

    UIImageView *cricleV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    
    UIImageView *bgImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    
    UIImageView *bigHouse = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    
    UILabel *lbl = [UILabel cz_labelWithText:@"注册登录注册登录注册登录注册登录注册登录注册登录注册登录注册登录" fontSize:15 color:[UIColor darkGrayColor]];
    lbl.preferredMaxLayoutWidth = 220;
  
    UIButton *registerBtn = [UIButton textButton:@"注册" fontSize:17 normalColor:[UIColor darkGrayColor] backgroundImage:@"common_button_white"];
    
    UIButton *loginBtn = [UIButton textButton:@"登录" fontSize:17 normalColor:[UIColor orangeColor] backgroundImage:@"common_button_white"];
    
    [registerBtn addTarget:self action:@selector(registerClick) forControlEvents:UIControlEventTouchUpInside];
    
    [loginBtn addTarget:self action:@selector(loginClick) forControlEvents:UIControlEventTouchUpInside];
    
    self.bigImg = cricleV;
    self.titleLab = lbl;
    self.bigHouse = bigHouse;
    self.bgImg = bgImg;
    
    [self addSubview:cricleV];
    [self addSubview:bgImg];
    [self addSubview:bigHouse];
    [self addSubview:lbl];
    [self addSubview:registerBtn];
    [self addSubview:loginBtn];
    
    //设置约束
    [cricleV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(-80);
        
    }];
    
    [bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.center.equalTo(cricleV);
    }];
    
    [bigHouse mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.center.equalTo(cricleV);
    }];
    
    [lbl mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(self);
        make.top.equalTo(cricleV.mas_bottom).offset(30);
    }];
    
    [registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(cricleV).offset(-20);
        make.top.equalTo(lbl.mas_bottom).offset(20);
        make.width.offset(80);
    }];
    
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(cricleV).offset(20);
        make.top.equalTo(lbl.mas_bottom).offset(20);
        make.width.offset(80);
    }];
    
    
    self.backgroundColor = [UIColor colorWithWhite:237/255.0 alpha:1];
    
}

-(void)title:(NSString *)title imageName:(NSString *)imageName isHome:(BOOL)isHome{

    self.bigImg.image = [UIImage imageNamed:imageName];
    self.titleLab.text = title;
    
    if (isHome) {
        
        [self setAnimation];
        
    }else{
        
        self.bigHouse.hidden = true;
        self.bgImg.hidden = true;
        
    }
}


/**
 设置首页动画
 */
-(void)setAnimation{

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    
    animation.toValue = @(M_PI * 2);
    animation.repeatCount = MAXFLOAT;
    animation.duration = 40;
    
    //动画不移除，一直保持动画
    animation.removedOnCompletion = NO;
    
    [self.bigImg.layer addAnimation:animation forKey:nil];
    
}


#pragma mark : - 按钮点击
-(void)registerClick{

    if (_registerBlock != nil) {
        
        _registerBlock();
    }

}

-(void)loginClick{

    if (_loginBlock != nil) {
        
        _loginBlock();
    }

}












@end
